package com.foreverwin.jzymes.qc.sample.controller;

import com.foreverwin.jzymes.common.service.IItemGroupAdviceService;
import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import com.foreverwin.jzymes.framework.base.BaseController;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.qc.sample.domain.SampleData;
import com.foreverwin.jzymes.qc.sample.service.ISampleDataAdiviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/qc/sample")
public class SampleController extends BaseController {
    @Autowired
    ISampleDataAdiviceService iSampleDataAdiviceService;
    @Autowired
    IItemGroupAdviceService iItemGroupAdviceService;

    /**
     * 增加样品信息
     * @param  sampleData
     * return
     */
    @RequestMapping("/submit")
    public AjaxResult submit(@RequestBody SampleData sampleData){
        try{
             sampleData.setSite( CommonMethods.getSite() );
            iSampleDataAdiviceService.insertSample( sampleData );
            return AjaxResult.returnSuccess().put("value",sampleData);
        }catch (BusinessException e ) {
            return AjaxResult.returnError( e.getMessage() );
        }
    }

    /**
     * 编辑样品信息
     * @param handle
     * @param sampleStu
     * @param disposition
     * @param quitUserBo
     * @param register
     * @return
     */
    @RequestMapping("/edit")
    public  AjaxResult editSample(@RequestParam String handle ,@RequestParam String sampleStu,@RequestParam String disposition,@RequestParam String quitUserBo,@RequestParam String register){
        try{

            SampleData sampleData = iSampleDataAdiviceService.editSample( handle,sampleStu,disposition,quitUserBo ,register);
            return AjaxResult.returnSuccess().put("value",sampleData);
        }catch (BusinessException e){
            return  AjaxResult.returnError(e.getMessage());
        }
    }

    /**
     * 查找样品信息
     * @param jsonMap
     * @return
     */
    @RequestMapping("/retrieve")
    public  AjaxResult search(@RequestParam Map<String,Object> jsonMap){
       try{
           jsonMap.put("site",CommonMethods.getSite());
          List<SampleData> sampleData = iSampleDataAdiviceService.selectSample( jsonMap );
           return AjaxResult.returnSuccess().put("value",sampleData);
       }catch (BusinessException e){
           return  AjaxResult.returnError(e.getMessage());
       }
    }


    /**
     * 样品删除
     * @param  handlelist
     * return
     */
    @RequestMapping("/deleteSampleData")
    public AjaxResult deleteSampleData(@RequestBody List< String > handlelist)  {
        try{
            iSampleDataAdiviceService.deleteSampleData( handlelist );
            return AjaxResult.returnSuccess();
        }catch (BusinessException e ) {
            return AjaxResult.returnError( e.getMessage() );
        }
    }
}
